﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using LayuiDemo.Models;


namespace LayuiDemo.tms.ViewModels.DriverTruckVMs
{
    public partial class DriverTruckListVM : BasePagedListVM<DriverTruck_View, DriverTruckSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "tms", dialogWidth: 800),
                this.MakeStandardAction("DriverTruck", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "tms"),
            };
        }


        protected override IEnumerable<IGridColumn<DriverTruck_View>> InitGridHeader()
        {
            return new List<GridColumn<DriverTruck_View>>{
                this.MakeGridHeader(x => x.DriverName_view),
                this.MakeGridHeader(x => x.TruckName_view),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<DriverTruck_View> GetSearchQuery()
        {
            var query = DC.Set<DriverTruck>()
                .CheckEqual(Searcher.DriverId, x=>x.DriverId)
                .CheckEqual(Searcher.TruckId, x=>x.TruckId)
                .Select(x => new DriverTruck_View
                {
				    ID = x.ID,
                    DriverName_view = x.Driver.DriverName,
                    TruckName_view = x.Truck.TruckName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class DriverTruck_View : DriverTruck{
        public String DriverName_view { get; set; }
        public String TruckName_view { get; set; }

    }
}
